var mongoose = require('mongoose');
mongoose.connect(mongoose.connect('mongodb://172.96.194.157:27017/babel'));

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', () => {
    console.log('we are connected!');
});

var userSchema = mongoose.Schema({
    username: String,
    password: String
});

var userModel = mongoose.model('user', userSchema);

//添加管理员帐号
// var adminAccount = {username : 'admin', password : 'biantaijiamian'};
// userModel.findOne({username:'admin'},function(err,doc){
// 	if(doc){
// 		console.log('find admin--->', doc);
// 		return;
// 	}
// 	userModel.create(adminAccount, function(error){
// 	    if(error) {
// 	       console.log(error);
// 	    } else {
//             console.log('save ok');
// 	    }
// 	    // 关闭数据库链接
// 	    db.close();
// 	});	
// })

module.exports = {
    userModel
}